//
//  JCLNavigationController.swift
//  WeiBo
//
//  Created by DDC on 2017/9/6.
//  Copyright © 2017年 DDC. All rights reserved.
//

import UIKit

class JCLNavigationController: UINavigationController {

    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        navigationBar.isHidden = true
        
        
    }
    // MARK:  - 重写push方法
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
//        print(viewController)
        //添加导航栏返回按钮
        if childViewControllers.count > 0 {
            
            if let vc = viewController as? JCLBaseViewController{
                //设置
                var title:String
                if childViewControllers.count == 1 {
                    
                    title = childViewControllers.first?.title ?? ""
                } else
                {
                    title = "返回"
                }
                
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, fontSize: 16, taret: self, action: #selector(popToParent))
            }
            
            viewController.hidesBottomBarWhenPushed = true
        }
        
        super.pushViewController(viewController, animated: true)
    }
// MARK:  - 返回按钮点击事件
    func popToParent(){
        popViewController(animated: true)
    }

}
